package com.bhs.sansong.ui.dialog;

import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.bhs.sansong.R;
import com.lxj.xpopup.core.BottomPopupView;

/**
 *评论弹窗
 */
public class CommentInputDialog extends BottomPopupView implements View.OnClickListener {

    private EditText mEtComment;
    private Button mTvIssue;


    public CommentInputDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_comment_input;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        mEtComment = findViewById(R.id.et_comment);

        mEtComment.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                boolean verify = editable.length() > 0;
                mTvIssue.setEnabled(verify);
                mTvIssue.setBackgroundColor(verify ? Color.parseColor("#485EF4") : Color.parseColor("#7F485EF4"));
            }
        });
        initView();
    }

    private MyClickListener2 listener;

    public void setMyClickListener(@Nullable MyClickListener2 l) {
        this.listener = l;
    }

    @Override
    public void onClick(View view) {
        dismiss();
        listener.onClick("", mEtComment.getText().toString());
    }

    private void initView() {
        mEtComment = findViewById(R.id.et_comment);
        mTvIssue = findViewById(R.id.tv_issue);
        mTvIssue.setOnClickListener(this);
    }
}
